﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace FYPDemo
{
    public partial class SurveyFeedback : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindVendorDDL();

                if (Convert.ToInt32(Session["isLogin"]) == 1)
                {
                    btnSubmit.Enabled = true;
                }
            }
        }

        public void bindVendorDDL()
        {
            DataTable dt = Survey.listVendor();
            ddlVendor.DataSource = dt;
            ddlVendor.DataTextField = "Name";
            ddlVendor.DataValueField = "ID";
            ddlVendor.DataBind();
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            int A1, A2, A3, A4, A5;
            int result = 0;
            string comment = "";
            int vendor = Convert.ToInt32(ddlVendor.SelectedValue);

            if (Session["username"] != null)
            {
                string name = Session["username"].ToString();

                A1 = Convert.ToInt32(rbA1.SelectedValue);
                A2 = Convert.ToInt32(rbA2.SelectedValue);
                A3 = Convert.ToInt32(rbA3.SelectedValue);
                A4 = Convert.ToInt32(rbA4.SelectedValue);
                A5 = Convert.ToInt32(rbA5.SelectedValue);
                comment = txtComment.Text;

                result = Survey.insertSurveyFeedback(name, vendor, A1, A2, A3, A4, A5, comment);

                if (result == 0)
                {
                    MessageBox.Show("Sorry that that error occured. Please try again later. You can contact our support team too.");
                }
            }
        }

    }
}